<?php

use Biz\model\activity\PageModule;
use Biz\service\activity\Page;
use Biz\service\brand\BlindBox;

/**
 * 盲盒活动页（「开工利是」特别版活动）
 */
class ActivityAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $pageId = $this->getRequest()->getQuery('page_id', 0);
        $pageInfo = Page::getPageInfo($pageId);
        $data = null;
        if ($pageInfo && $pageInfo['module_list']) {
            $blindBoxModule = [];
            foreach ($pageInfo['module_list'] as $row) {
                if ($row['type'] == PageModule::MODULE_TYPE_BLIND_BOX) {
                    $blindBoxModule = $row['module'];
                    break;
                }
            }
            if ($blindBoxModule) {
                $boxInfo = BlindBox::getUserBox($this->uid, BlindBox::SOURCE_H5_ACTIVITY);
                $boxMap = BlindBox::getBlindBox($this->uid);
                $boxList = array_values($boxMap);
                $boxList[] = $boxMap[$boxInfo['box_id']];
                $data = [
                    'box_info' => $boxInfo,
                    'box_list' => $boxList,
                    'module' => [
                        'bg_img' => $blindBoxModule['bg_img'],
                        'btn_img' => [
                            'before' => $blindBoxModule['btn_before'],
                            'after' => $blindBoxModule['btn_after'],
                        ]
                    ]
                ];
            }
        }
        $this->setSuccess($data);
    }
}